using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;


namespace GameWP
{
    public class AboutComponent : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Game _game;
        private SpriteBatch _spriteBatch;
        private SpriteFont _menuFont, _textFont;
        private Vector2 touchPosition, pretouchPosition;
        List<Button> _listItemMenu;
        private Button _info, _cheatcodeButton;
        public List<Button> ListItemMenu
        {
            get { return _listItemMenu; }
            set { _listItemMenu = value; }
        }


        //Initilation
        public AboutComponent(Game game, SpriteFont spriteFont, SpriteFont textFont, SpriteBatch spriteBatch)
            : base(game)
        {
            _game = game;
            _menuFont = spriteFont;
            _textFont = textFont;
            _spriteBatch = spriteBatch;

            //Init list menu item
            string infoText = "Author: \n - Dang Nhat Duy \n - Phan Nguyen Dat \nVersion: 1.0\nContact: 01699639139";
            ListItemMenu = new List<Button>();
            ListItemMenu.Add(new Button("Back", _menuFont, new Vector2(690, 410), Color.Red));
            _info = new Button(infoText, _textFont, new Vector2(400,200), Color.White) { HaveAnimation = false };

            //Cheatcode menu
            _cheatcodeButton = new Button(".", _textFont, new Vector2(140, 250), Color.Black) { HaveAnimation = false };
            _cheatcodeButton.Selected += new Button.IsSelected(_cheatcodeButton_Selected);
        }

        void _cheatcodeButton_Selected(int input)
        {
            ManagerGame.luffy.Balance = 999999;
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here
                base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here    
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                _game.Exit();
            //Key input
            TouchCollection touchCollection = TouchPanel.GetState();
            touchPosition = Vector2.Zero;
            if (touchCollection.Count > 0)
            {
                touchPosition = touchCollection[0].Position;
                pretouchPosition = touchPosition;
            }

            _cheatcodeButton.ButtonIsTouched(touchPosition, 0);

            for (int i = 0; i < ListItemMenu.Count; i++)
                ListItemMenu[i].ButtonIsTouched(touchPosition, i);
                base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            _info.Draw(_spriteBatch, gameTime);
            for (int i = 0; i < ListItemMenu.Count; i++)
                ListItemMenu[i].Draw(_spriteBatch, gameTime);
            _cheatcodeButton.Draw(_spriteBatch, gameTime);
        }
    }
}
